import unittest
import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By


class A3mall(unittest.TestCase):
    def setUp(self):
        # 准备环境
        self.driver = webdriver.Edge()
        self.driver.get('http://10.59.9.14:7003/')
        self.driver.maximize_window()
        driver = webdriver.Edge()
        driver.get('http://10.59.9.14:7003/')
        driver.maximize_window()
        # 隐示等待
        driver.implicitly_wait(5)
        # 登录
        driver.find_element(By.LINK_TEXT, '登录').click()
        # 强制等待
        time.sleep(2)
        # 合理使用输入指令

        pwd = driver.find_element(By.CLASS_NAME, 'regi-input')
        # # 合理使用清空指令
        pwd.clear()
        pwd.send_keys('18986670716')
        time.sleep(2)

        # 5.获取元素的文字
        print(pwd.get_attribute('value'))
        driver.find_element(By.NAME, 'password').send_keys('a123456')
        time.sleep(10)
        # 合理使用点击指令
        driver.find_element(By.CLASS_NAME, 'finish-btn').click()
        time.sleep(5)
        # 搜索
        search = driver.find_element(By.CLASS_NAME, 'search-input')
        # time.sleep(2)
        # 合理使用输入指令
        search.send_keys('龙虾')
        time.sleep(2)
        search.send_keys(Keys.ENTER)
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/em/a').click()
        time.sleep(2)
        # # 合理使用点击指令
        driver.find_element(By.ID, 'add-cart').click()
        time.sleep(6)

if __name__ == '__main__':
    unittest.main()